home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FishMarket 1.0
/
FishMarket v1.0.iso
/
fishies
/
551-575
/
disk_562
/
intuisup
/
editor
/
source.lzh
/
window.c
< prev
Wrap
C/C++ Source or Header
|
1991-10-20
|
15KB
|
406 lines
/*************************************
* *
* Editor v1.0 *
* by Torsten Jürgeleit in 09/91 *
* *
* Window part *
* *
*************************************/
/* Includes */
#include "includes.h"
#include "defines.h"
#include "imports.h"
#include "protos.h"
/* Defines for window gadgets */
#define WINDOW_TITLE_LEFT_EDGE 0
#define WINDOW_TITLE_TOP_EDGE 10
#define WINDOW_TITLE_TYPE TEXT_DATA_TYPE_TEXT
#define WINDOW_TITLE_FLAGS (TEXT_DATA_FLAG_CENTER | TEXT_DATA_FLAG_BOLD)
#define WINDOW_TITLE_TEXT_ATTR &topaz80_attr
#define WINDOW_TITLE_TEXT "Change project window"
/* Defines for window gadgets */
#define WINDOW_GADGET_OK 0
#define WINDOW_GADGET_CANCEL 1
#define WINDOW_GADGET_LEFT_EDGE 2
#define WINDOW_GADGET_TOP_EDGE 3
#define WINDOW_GADGET_WIDTH 4
#define WINDOW_GADGET_HEIGHT 5
#define WINDOW_GADGET_RESIZING 6
#define WINDOW_GADGET_BACK_FILL 7
#define WINDOW_GADGET_RENDER_COLORS 8
#define WINDOW_GADGET1_TYPE GADGET_DATA_TYPE_BUTTON
#define WINDOW_GADGET1_FLAGS GADGET_DATA_FLAG_HOT_KEY
#define WINDOW_GADGET1_TEXT "_Ok"
#define WINDOW_GADGET1_LEFT_EDGE ((EDITOR_WINDOW_WIDTH / 2 - WINDOW_GADGET1_WIDTH) / 2)
#define WINDOW_GADGET1_TOP_EDGE (EDITOR_WINDOW_HEIGHT - WINDOW_GADGET1_HEIGHT - 10)
#define WINDOW_GADGET1_WIDTH ((6 + 2) * 8)
#define WINDOW_GADGET1_HEIGHT 15
#define WINDOW_GADGET1_TEXT_ATTR &topaz80_attr
#define WINDOW_GADGET2_TYPE GADGET_DATA_TYPE_BUTTON
#define WINDOW_GADGET2_FLAGS GADGET_DATA_FLAG_HOT_KEY
#define WINDOW_GADGET2_TEXT "_Cancel"
#define WINDOW_GADGET2_LEFT_EDGE (EDITOR_WINDOW_WIDTH / 2 + (EDITOR_WINDOW_WIDTH / 2 - WINDOW_GADGET1_WIDTH) / 2)
#define WINDOW_GADGET2_TOP_EDGE (EDITOR_WINDOW_HEIGHT - WINDOW_GADGET1_HEIGHT - 10)
#define WINDOW_GADGET2_WIDTH WINDOW_GADGET1_WIDTH
#define WINDOW_GADGET2_HEIGHT WINDOW_GADGET1_HEIGHT
#define WINDOW_GADGET2_TEXT_ATTR &topaz80_attr
#define WINDOW_GADGET3_TYPE GADGET_DATA_TYPE_INTEGER
#define WINDOW_GADGET3_FLAGS (GADGET_DATA_FLAG_HOT_KEY | GADGET_DATA_FLAG_TEXT_LEFT | GADGET_DATA_FLAG_INPUT_AUTO_ACTIVATE)
#define WINDOW_GADGET3_LEFT_EDGE (20 + (9 + 1) * 8)
#define WINDOW_GADGET3_TOP_EDGE 20
#define WINDOW_GADGET3_WIDTH 52
#define WINDOW_GADGET3_HEIGHT 12
#define WINDOW_GADGET3_TEXT "_Left edge"
#define WINDOW_GADGET3_TEXT_ATTR &topaz80_attr
#define WINDOW_GADGET3_INPUT_LEN 5
#define WINDOW_GADGET3_INPUT_ACTIVATE ((ULONG)WINDOW_GADGET_TOP_EDGE << 16 | WINDOW_GADGET_HEIGHT)
#define WINDOW_GADGET3_INPUT_DEFAULT NULL
#define WINDOW_GADGET4_TYPE GADGET_DATA_TYPE_INTEGER
#define WINDOW_GADGET4_FLAGS (GADGET_DATA_FLAG_HOT_KEY | GADGET_DATA_FLAG_TEXT_LEFT | GADGET_DATA_FLAG_INPUT_AUTO_ACTIVATE)
#define WINDOW_GADGET4_LEFT_EDGE WINDOW_GADGET3_LEFT_EDGE
#define WINDOW_GADGET4_TOP_EDGE (WINDOW_GADGET3_TOP_EDGE + WINDOW_GADGET3_HEIGHT + 4)
#define WINDOW_GADGET4_WIDTH WINDOW_GADGET3_WIDTH
#define WINDOW_GADGET4_HEIGHT WINDOW_GADGET3_HEIGHT
#define WINDOW_GADGET4_TEXT "_Top edge"
#define WINDOW_GADGET4_TEXT_ATTR &topaz80_attr
#define WINDOW_GADGET4_INPUT_LEN 5
#define WINDOW_GADGET4_INPUT_ACTIVATE ((ULONG)WINDOW_GADGET_WIDTH << 16 | WINDOW_GADGET_LEFT_EDGE)
#define WINDOW_GADGET4_INPUT_DEFAULT NULL
#define WINDOW_GADGET5_TYPE GADGET_DATA_TYPE_INTEGER
#define WINDOW_GADGET5_FLAGS (GADGET_DATA_FLAG_HOT_KEY | GADGET_DATA_FLAG_TEXT_LEFT | GADGET_DATA_FLAG_INPUT_AUTO_ACTIVATE)
#define WINDOW_GADGET5_LEFT_EDGE WINDOW_GADGET3_LEFT_EDGE
#define WINDOW_GADGET5_TOP_EDGE (WINDOW_GADGET4_TOP_EDGE + WINDOW_GADGET3_HEIGHT + 4)
#define WINDOW_GADGET5_WIDTH WINDOW_GADGET3_WIDTH
#define WINDOW_GADGET5_HEIGHT WINDOW_GADGET3_HEIGHT
#define WINDOW_GADGET5_TEXT "_Width"
#define WINDOW_GADGET5_TEXT_ATTR &topaz80_attr
#define WINDOW_GADGET5_INPUT_LEN 5
#define WINDOW_GADGET5_INPUT_ACTIVATE ((ULONG)WINDOW_GADGET_HEIGHT << 16 | WINDOW_GADGET_TOP_EDGE)
#define WINDOW_GADGET5_INPUT_DEFAULT NULL
#define WINDOW_GADGET6_TYPE GADGET_DATA_TYPE_INTEGER
#define WINDOW_GADGET6_FLAGS (GADGET_DATA_FLAG_HOT_KEY | GADGET_DATA_FLAG_TEXT_LEFT | GADGET_DATA_FLAG_INPUT_AUTO_ACTIVATE)
#define WINDOW_GADGET6_LEFT_EDGE WINDOW_GADGET3_LEFT_EDGE
#define WINDOW_GADGET6_TOP_EDGE (WINDOW_GADGET5_TOP_EDGE + WINDOW_GADGET3_HEIGHT + 4)
#define WINDOW_GADGET6_WIDTH WINDOW_GADGET3_WIDTH
#define WINDOW_GADGET6_HEIGHT WINDOW_GADGET3_HEIGHT
#define WINDOW_GADGET6_TEXT "_Height"
#define WINDOW_GADGET6_TEXT_ATTR &topaz80_attr
#define WINDOW_GADGET6_INPUT_LEN 5
#define WINDOW_GADGET6_INPUT_ACTIVATE ((ULONG)WINDOW_GADGET_LEFT_EDGE << 16 | WINDOW_GADGET_WIDTH)
#define WINDOW_GADGET6_INPUT_DEFAULT NULL
#define WINDOW_GADGET7_TYPE GADGET_DATA_TYPE_CHECK
#define WINDOW_GADGET7_FLAGS (GADGET_DATA_FLAG_HOT_KEY | GADGET_DATA_FLAG_TEXT_RIGHT)
#define WINDOW_GADGET7_TEXT "_Resizing gadget"
#define WINDOW_GADGET7_LEFT_EDGE (WINDOW_GADGET3_LEFT_EDGE + WINDOW_GADGET3_WIDTH + 80)
#define WINDOW_GADGET7_TOP_EDGE (WINDOW_GADGET3_TOP_EDGE + 1)
#define WINDOW_GADGET7_WIDTH 0
#define WINDOW_GADGET7_HEIGHT 0
#define WINDOW_GADGET7_TEXT_ATTR &topaz80_attr
#define WINDOW_GADGET8_TYPE GADGET_DATA_TYPE_CHECK
#define WINDOW_GADGET8_FLAGS (GADGET_DATA_FLAG_HOT_KEY | GADGET_DATA_FLAG_TEXT_RIGHT)
#define WINDOW_GADGET8_TEXT "_Fill background"
#define WINDOW_GADGET8_LEFT_EDGE WINDOW_GADGET7_LEFT_EDGE
#define WINDOW_GADGET8_TOP_EDGE (WINDOW_GADGET7_TOP_EDGE + 25)
#define WINDOW_GADGET8_WIDTH 0
#define WINDOW_GADGET8_HEIGHT 0
#define WINDOW_GADGET8_TEXT_ATTR &topaz80_attr
#define WINDOW_GADGET9_TYPE GADGET_DATA_TYPE_CHECK
#define WINDOW_GADGET9_FLAGS (GADGET_DATA_FLAG_HOT_KEY | GADGET_DATA_FLAG_TEXT_RIGHT)
#define WINDOW_GADGET9_TEXT "_Use render colors"
#define WINDOW_GADGET9_LEFT_EDGE WINDOW_GADGET7_LEFT_EDGE
#define WINDOW_GADGET9_TOP_EDGE (WINDOW_GADGET8_TOP_EDGE + 25)
#define WINDOW_GADGET9_WIDTH 0
#define WINDOW_GADGET9_HEIGHT 0
#define WINDOW_GADGET9_TEXT_ATTR &topaz80_attr
/* Statics for window requester */
STATIC struct GadgetData window_gadget_data[] = {
{
WINDOW_GADGET1_TYPE, /* gd_Type */
WINDOW_GADGET1_FLAGS, /* gd_Flags */
WINDOW_GADGET1_LEFT_EDGE, /* gd_LeftEdge */
WINDOW_GADGET1_TOP_EDGE, /* gd_TopEdge */
WINDOW_GADGET1_WIDTH, /* gd_Width */
WINDOW_GADGET1_HEIGHT, /* gd_Height */
WINDOW_GADGET1_TEXT, /* *gd_Text */
WINDOW_GADGET1_TEXT_ATTR, /* *gd_TextAttr */
{ 0, 0, 0 }
}, {
WINDOW_GADGET2_TYPE, /* gd_Type */
WINDOW_GADGET2_FLAGS, /* gd_Flags */
WINDOW_GADGET2_LEFT_EDGE, /* gd_LeftEdge */
WINDOW_GADGET2_TOP_EDGE, /* gd_TopEdge */
WINDOW_GADGET2_WIDTH, /* gd_Width */
WINDOW_GADGET2_HEIGHT, /* gd_Height */
WINDOW_GADGET2_TEXT, /* *gd_Text */
WINDOW_GADGET2_TEXT_ATTR, /* *gd_TextAttr */
{ 0, 0, 0 }
}, {
WINDOW_GADGET3_TYPE, /* gd_Type */
WINDOW_GADGET3_FLAGS, /* gd_Flags */
WINDOW_GADGET3_LEFT_EDGE, /* gd_LeftEdge */
WINDOW_GADGET3_TOP_EDGE, /* gd_TopEdge */
WINDOW_GADGET3_WIDTH, /* gd_Width */
WINDOW_GADGET3_HEIGHT, /* gd_Height */
WINDOW_GADGET3_TEXT, /* *gd_Text */
WINDOW_GADGET3_TEXT_ATTR, /* *gd_TextAttr */
{
WINDOW_GADGET3_INPUT_LEN, /* gd_InputLen */
WINDOW_GADGET3_INPUT_ACTIVATE, /* gd_InputActivate */
WINDOW_GADGET3_INPUT_DEFAULT /* gd_InputDefault */
}
}, {
WINDOW_GADGET4_TYPE, /* gd_Type */
WINDOW_GADGET4_FLAGS, /* gd_Flags */
WINDOW_GADGET4_LEFT_EDGE, /* gd_LeftEdge */
WINDOW_GADGET4_TOP_EDGE, /* gd_TopEdge */
WINDOW_GADGET4_WIDTH, /* gd_Width */
WINDOW_GADGET4_HEIGHT, /* gd_Height */
WINDOW_GADGET4_TEXT, /* *gd_Text */
WINDOW_GADGET4_TEXT_ATTR, /* *gd_TextAttr */
{
WINDOW_GADGET4_INPUT_LEN, /* gd_InputLen */
WINDOW_GADGET4_INPUT_ACTIVATE, /* gd_InputActivate */
WINDOW_GADGET4_INPUT_DEFAULT /* gd_InputDefault */
}
}, {
WINDOW_GADGET5_TYPE, /* gd_Type */
WINDOW_GADGET5_FLAGS, /* gd_Flags */
WINDOW_GADGET5_LEFT_EDGE, /* gd_LeftEdge */
WINDOW_GADGET5_TOP_EDGE, /* gd_TopEdge */
WINDOW_GADGET5_WIDTH, /* gd_Width */
WINDOW_GADGET5_HEIGHT, /* gd_Height */
WINDOW_GADGET5_TEXT, /* *gd_Text */
WINDOW_GADGET5_TEXT_ATTR, /* *gd_TextAttr */
{
WINDOW_GADGET5_INPUT_LEN, /* gd_InputLen */
WINDOW_GADGET5_INPUT_ACTIVATE, /* gd_InputActivate */
WINDOW_GADGET5_INPUT_DEFAULT /* gd_InputDefault */
}
}, {
WINDOW_GADGET6_TYPE, /* gd_Type */
WINDOW_GADGET6_FLAGS, /* gd_Flags */
WINDOW_GADGET6_LEFT_EDGE, /* gd_LeftEdge */
WINDOW_GADGET6_TOP_EDGE, /* gd_TopEdge */
WINDOW_GADGET6_WIDTH, /* gd_Width */
WINDOW_GADGET6_HEIGHT, /* gd_Height */
WINDOW_GADGET6_TEXT, /* *gd_Text */
WINDOW_GADGET6_TEXT_ATTR, /* *gd_TextAttr */
{
WINDOW_GADGET6_INPUT_LEN, /* gd_InputLen */
WINDOW_GADGET6_INPUT_ACTIVATE, /* gd_InputActivate */
WINDOW_GADGET6_INPUT_DEFAULT /* gd_InputDefault */
}
}, {
WINDOW_GADGET7_TYPE, /* gd_Type */
WINDOW_GADGET7_FLAGS, /* gd_Flags */
WINDOW_GADGET7_LEFT_EDGE, /* gd_LeftEdge */
WINDOW_GADGET7_TOP_EDGE, /* gd_TopEdge */
WINDOW_GADGET7_WIDTH, /* gd_Width */
WINDOW_GADGET7_HEIGHT, /* gd_Height */
WINDOW_GADGET7_TEXT, /* *gd_Text */
WINDOW_GADGET7_TEXT_ATTR, /* *gd_TextAttr */
{ 0, 0, 0 }
}, {
WINDOW_GADGET8_TYPE, /* gd_Type */
WINDOW_GADGET8_FLAGS, /* gd_Flags */
WINDOW_GADGET8_LEFT_EDGE, /* gd_LeftEdge */
WINDOW_GADGET8_TOP_EDGE, /* gd_TopEdge */
WINDOW_GADGET8_WIDTH, /* gd_Width */
WINDOW_GADGET8_HEIGHT, /* gd_Height */
WINDOW_GADGET8_TEXT, /* *gd_Text */
WINDOW_GADGET8_TEXT_ATTR, /* *gd_TextAttr */
{ 0, 0, 0 }
}, {
WINDOW_GADGET9_TYPE, /* gd_Type */
WINDOW_GADGET9_FLAGS, /* gd_Flags */
WINDOW_GADGET9_LEFT_EDGE, /* gd_LeftEdge */
WINDOW_GADGET9_TOP_EDGE, /* gd_TopEdge */
WINDOW_GADGET9_WIDTH, /* gd_Width */
WINDOW_GADGET9_HEIGHT, /* gd_Height */
WINDOW_GADGET9_TEXT, /* *gd_Text */
WINDOW_GADGET9_TEXT_ATTR, /* *gd_TextAttr */
{ 0, 0, 0 }
}, {
INTUISUP_DATA_END /* mark end of gadget data */
}
};
/* Change settings for project window */
SHORT
change_project_window(VOID)
{
struct GadgetData *gd = &window_gadget_data[0];
APTR gl;
USHORT flags = template_list.tl_Flags;
SHORT status;
/* Init integer gadgets with current project window dimension */
(gd + WINDOW_GADGET_LEFT_EDGE)->gd_SpecialData.gd_InputData.gd_InputDefault = (BYTE *)pwin->LeftEdge;
(gd + WINDOW_GADGET_TOP_EDGE)->gd_SpecialData.gd_InputData.gd_InputDefault = (BYTE *)pwin->TopEdge;
(gd + WINDOW_GADGET_WIDTH)->gd_SpecialData.gd_InputData.gd_InputDefault = (BYTE *)pwin->Width;
(gd + WINDOW_GADGET_HEIGHT)->gd_SpecialData.gd_InputData.gd_InputDefault = (BYTE *)pwin->Height;
(gd + WINDOW_GADGET_RESIZING)->gd_SpecialData.gd_CheckData.gd_CheckSelected = (flags & TEMPLATE_LIST_FLAG_RESIZING ? 1 : 0);
(gd + WINDOW_GADGET_BACK_FILL)->gd_SpecialData.gd_CheckData.gd_CheckSelected = (flags & TEMPLATE_LIST_FLAG_BACK_FILL ? 1 : 0);
(gd + WINDOW_GADGET_RENDER_COLORS)->gd_SpecialData.gd_CheckData.gd_CheckSelected = (flags & TEMPLATE_LIST_FLAG_RENDER_COLORS ? 1 : 0);
/* Print title and display gadgets */
IClearRenderWindow(eri, ewin, 0, 0, -1, -1);
IPrintText(eri, ewin, WINDOW_TITLE_TEXT, WINDOW_TITLE_LEFT_EDGE,
WINDOW_TITLE_TOP_EDGE, WINDOW_TITLE_TYPE, WINDOW_TITLE_FLAGS,
WINDOW_TITLE_TEXT_ATTR);
if (!(gl = ICreateGadgets(eri, &window_gadget_data[0], 0, 0))) {
status = EDITOR_ERROR_OUT_OF_MEM;
} else {
IDisplayGadgets(ewin, gl);
status = change_project_window_action(gl);
IRemoveGadgets(gl);
IFreeGadgets(gl);
}
return(status);
}
/* Perform action for change project window settings */
STATIC SHORT
change_project_window_action(APTR gl)
{
struct TemplateList *tl = &template_list;
struct MsgPort *up = ewin->UserPort;
struct IntuiMessage *msg;
struct NewWindow *nwin = &project_new_window;
USHORT left_edge = pwin->LeftEdge, top_edge = pwin->TopEdge,
width = pwin->Width, height = pwin->Height,
max_width = wb_screen.Width, max_height = wb_screen.Height,
flags = tl->tl_Flags;
ULONG value;
BOOL keepon = TRUE;
SHORT status = EDITOR_STATUS_NORMAL;
do {
WaitPort(up);
while (msg = IGetMsg(up)) {
switch (msg->Class) {
case CLOSEWINDOW :
status = EDITOR_STATUS_QUIT;
keepon = FALSE;
break;
case ISUP_ID :
value = (ULONG)msg->IAddress;
switch (msg->Code) {
case WINDOW_GADGET_OK :
/* Change project window */
nwin->LeftEdge = left_edge;
nwin->TopEdge = top_edge;
nwin->Width = width;
nwin->Height = height;
tl->tl_Flags = flags;
if ((status = new_project_window(flags)) ==
EDITOR_STATUS_NORMAL) {
refresh_all_templates();
}
keepon = FALSE;
break;
case WINDOW_GADGET_CANCEL :
keepon = FALSE;
break;
case WINDOW_GADGET_LEFT_EDGE :
if ((value + width) > max_width) {
DisplayBeep(NULL);
ISetGadgetAttributes(gl, WINDOW_GADGET_LEFT_EDGE,
0L, USE_CURRENT_VALUE, USE_CURRENT_VALUE,
(BYTE *)left_edge);
} else {
left_edge = value;
flags |= TEMPLATE_LIST_FLAG_CHANGED;
}
break;
case WINDOW_GADGET_TOP_EDGE :
if ((value + height) > max_height) {
DisplayBeep(NULL);
ISetGadgetAttributes(gl, WINDOW_GADGET_TOP_EDGE,
0L, USE_CURRENT_VALUE, USE_CURRENT_VALUE,
(BYTE *)top_edge);
} else {
top_edge = value;
flags |= TEMPLATE_LIST_FLAG_CHANGED;
}
break;
case WINDOW_GADGET_WIDTH :
if ((left_edge + value) > max_width) {
DisplayBeep(NULL);
ISetGadgetAttributes(gl, WINDOW_GADGET_WIDTH,
0L, USE_CURRENT_VALUE, USE_CURRENT_VALUE,
(BYTE *)width);
} else {
width = value;
flags |= TEMPLATE_LIST_FLAG_CHANGED;
}
break;
case WINDOW_GADGET_HEIGHT :
if ((top_edge + value) > max_height) {
DisplayBeep(NULL);
ISetGadgetAttributes(gl, WINDOW_GADGET_HEIGHT,
0L, USE_CURRENT_VALUE, USE_CURRENT_VALUE,
(BYTE *)height);
} else {
height = value;
flags |= TEMPLATE_LIST_FLAG_CHANGED;
}
break;
case WINDOW_GADGET_RESIZING :
if (value) {
flags |= TEMPLATE_LIST_FLAG_RESIZING;
} else {
flags &= ~TEMPLATE_LIST_FLAG_RESIZING;
}
flags |= TEMPLATE_LIST_FLAG_CHANGED;
break;
case WINDOW_GADGET_BACK_FILL :
if (value) {
flags |= TEMPLATE_LIST_FLAG_BACK_FILL;
} else {
flags &= ~TEMPLATE_LIST_FLAG_BACK_FILL;
}
flags |= TEMPLATE_LIST_FLAG_CHANGED;
break;
case WINDOW_GADGET_RENDER_COLORS :
if (value) {
flags |= TEMPLATE_LIST_FLAG_RENDER_COLORS;
} else {
flags &= ~TEMPLATE_LIST_FLAG_RENDER_COLORS;
}
flags |= TEMPLATE_LIST_FLAG_CHANGED;
break;
}
break;
}
}
} while (keepon == TRUE);
return(status);
}